package com.lonty.intelligence.controller;

import com.lonty.intelligence.api.Result;
import com.lonty.intelligence.api.ResultCode;
import com.lonty.intelligence.service.MicroDynamicService;
import com.lonty.intelligence.vo.MicroDynamicVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/7/7 10:47
 * @Version 1.0
 */
@RestController
@RequestMapping("app/microDynamic")
@Validated
@Api(tags = "微动态接口", produces = "application/json")
public class MicroDynamicController {

    @Resource
    private MicroDynamicService microDynamicService;

    @ApiOperation(value = "保存微动态", httpMethod = "POST")
    @PostMapping("saveMicroDynamic")
    public Result saveMicroDynamic(@ModelAttribute MicroDynamicVo microDynamicVo){
        if(microDynamicService.saveMicroDynamic(microDynamicVo)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "根据ID获取微动态", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "微动态id",dataType = "string", paramType = "query")
    })
    @GetMapping("getById")
    public Result getById(String id){
        return Result.builder()
                .data(microDynamicService.getById(id))
                .build();
    }

    @ApiOperation(value = "分页获取微动态", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页",dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页显示的数量",dataType = "int", paramType = "query")
    })
    @GetMapping("getMicroDynamicList")
    public Result getMicroDynamicList(Integer page, Integer size){
        return Result.builder()
                .data(microDynamicService.getMicroDynamicList(page, size))
                .build();
    }

    @ApiOperation(value = "删除微动态", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "微动态id",dataType = "string", paramType = "query")
    })
    @PostMapping("deleteMicroDynamic")
    public Result deleteMicroDynamic(String id){
        if(microDynamicService.deleteMicroDynamic(id)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "根据ID修改点击数量", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "微动态id",dataType = "string", paramType = "query")
    })
    @PostMapping("modifyNum")
    public Result modifyNum(String id){
        if(microDynamicService.modifyNum(id)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

}
